package club.janna.rpcdemo.server;

import club.janna.rpcdemo.server.annotation.EnableRPC;
import club.janna.rpcdemo.server.register.RPCMapping;
import club.janna.rpcdemo.server.register.ServiceRegister;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;
import java.util.Set;

@EnableRPC
@SpringBootApplication
public class ServerBootstrap {
    public static void main(String[] args) throws IOException {
        ConfigurableApplicationContext context = SpringApplication.run(ServerBootstrap.class);
        ServiceRegister serviceRegister = context.getBean(ServiceRegister.class);
        Set<String> services = RPCMapping.services();
        // 注册RPC服务
        for (String serviceName : services) {
            serviceRegister.register(serviceName, context.getBean(RPCMapping.getAndDelete(serviceName)));
        }
        System.in.read();
    }
}
